package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Collect;
import com.cskaoyan.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("wx/collect")
public class CollectController {

    private static Integer userId;

    static {
//        Subject subject = SecurityUtils.getSubject();
//        userId = (Integer) subject.getPrincipal();
        userId = 1;
    }

    @Autowired
    CollectService collectService;
    // 查看收藏
    // 未测试 TODO
    @GetMapping("list")
    public BaseRespVo list(Integer type,Integer page,Integer size){
        Map<String,Object> map = collectService.list(type,page,size,userId);
        return BaseRespVo.ok(map);
    }
    // 添加收藏
    // 未测试 TODO
    @PostMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody Collect collect){
        collect.setUserId(userId);
        Boolean b =collectService.addordelete(collect);
        Map<String, String> map = new HashMap<String, String>();
        if(b){
            map.put("type","add");
        }else{
            map.put("type","delete");
        }
        return BaseRespVo.ok(map);
    }
}













